home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Menu Repla185894202001.psc / MenuCtl.ctl (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-04-20  |  13.9 KB  |  347 lines

  1. VERSION 5.00
  2. Begin VB.UserControl MenuCtl 
  3.    CanGetFocus     =   0   'False
  4.    ClientHeight    =   480
  5.    ClientLeft      =   0
  6.    ClientTop       =   0
  7.    ClientWidth     =   480
  8.    InvisibleAtRuntime=   -1  'True
  9.    Picture         =   "MenuCtl.ctx":0000
  10.    ScaleHeight     =   480
  11.    ScaleWidth      =   480
  12.    ToolboxBitmap   =   "MenuCtl.ctx":08CA
  13. Attribute VB_Name = "MenuCtl"
  14. Attribute VB_GlobalNameSpace = False
  15. Attribute VB_Creatable = True
  16. Attribute VB_PredeclaredId = False
  17. Attribute VB_Exposed = True
  18. 'MenuCtl of Menu.ocx
  19. 'Created by Daniel Taylor on April 14, 2001
  20. 'This is the actual usercontrol, where the user will
  21. 'set all the properties later used by MenuFrm.frm
  22. 'I have a german version of VB, and most of the code is
  23. 'generated, so it has the german comments... just ignore them
  24. 'they are for the ActiveX Wizard thing...
  25. 'My code is probably very messy & unorganized & unoptimized,
  26. 'but the menu is running pretty fast now, almost as fast as
  27. 'the windows menus when the mouse if moved over them.
  28. 'The code may seem a bit confusing at first, but you need
  29. 'to also look at the MenuFrm.frm code to understand it all.
  30. 'also the variables are kept in a puclic module (Module1.bas)
  31. 'so they can be accessed by the usercontrol and menufrm
  32. Public Enum Style_Type
  33.     Etch_Style
  34.     OutDent_Style
  35.     PlainLine_Style
  36. End Enum
  37. Public Enum Sel_Type
  38.     Block
  39.     TextBlock
  40.     DottedTextBlock
  41. End Enum
  42. Private Type POINTAPI
  43.     X As Long
  44.     Y As Long
  45. End Type
  46. 'Standard-Eigenschaftswerte:
  47. Const m_def_MouseOverSelectionType = 0
  48. Const m_def_LeftPicBackColor = &H8000000F
  49. Const m_def_UseLeftImage = 0
  50. Const m_def_MenuAnimSpeed = 500
  51. Const m_def_OpenAnimated = 0
  52. Const m_def_UseIcons = 0
  53. Const m_def_ItemHotBackColor = &H8000000D
  54. Const m_def_Style = 0
  55. Const m_def_ItemForeColor = &H80000007
  56. Const m_def_ItemHotForeColor = &H8000000E
  57. 'Ereignisdeklarationen:
  58. Event ItemClicked(Index As Integer, Text As String, Name As String)
  59. 'api declarations
  60. Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
  61. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  62. 'properties
  63. Private m_ItemHotBackColor As OLE_COLOR
  64. Private m_ItemForeColor As OLE_COLOR
  65. Private m_ItemHotForeColor As OLE_COLOR
  66. Private Sub UserControl_Resize()
  67.     'just make the usercontrol a little icon, invisible at runtime
  68.     UserControl.Width = 480
  69.     UserControl.Height = 480
  70. End Sub
  71. 'ACHTUNG! DIE FOLGENDEN KOMMENTIERTEN ZEILEN NICHT ENTFERNEN ODER VER
  72. NDERN!
  73. 'MappingInfo=UserControl,UserControl,-1,Font
  74. Public Property Get Font() As Font
  75. Attribute Font.VB_Description = "Returns a Font object."
  76. Attribute Font.VB_UserMemId = -512
  77.     Set Font = UserControl.Font
  78. End Property
  79. Public Property Set Font(ByVal New_Font As Font)
  80.     Set UserControl.Font = New_Font
  81.     PropertyChanged "Font"
  82. End Property
  83. 'ACHTUNG! DIE FOLGENDEN KOMMENTIERTEN ZEILEN NICHT ENTFERNEN ODER VER
  84. NDERN!
  85. 'MappingInfo=UserControl,UserControl,-1,Enabled
  86. Public Property Get Enabled() As Boolean
  87. Attribute Enabled.VB_Description = "Returns/sets a value that determines whether an object can respond to user-generated events."
  88.     Enabled = UserControl.Enabled
  89. End Property
  90. Public Property Let Enabled(ByVal New_Enabled As Boolean)
  91.     UserControl.Enabled() = New_Enabled
  92.     PropertyChanged "Enabled"
  93. End Property
  94. 'ACHTUNG! DIE FOLGENDEN KOMMENTIERTEN ZEILEN NICHT ENTFERNEN ODER VER
  95. NDERN!
  96. 'MemberInfo=14
  97. Public Function AddItem(Caption As String, Optional Name As String = "", Optional Enabled As Boolean = True, Optional ItemIcon As StdPicture, Optional ItemForeColor As OLE_COLOR = -1, Optional ItemHotForeColor As OLE_COLOR = -1, Optional ItemHotBackColor As OLE_COLOR = -1) As Boolean
  98.     'Add an item to the menu...
  99.     ItemCount = ItemCount + 1
  100.     ReDim Preserve Items(ItemCount)
  101.     Items(ItemCount).Text = Caption
  102.     'if it's a seperator disable it, so it is a seperator later
  103.     If LCase(Name) <> "seperator" Then
  104.         Items(ItemCount).Enabled = Enabled
  105.     Else
  106.         Items(ItemCount).Enabled = False
  107.     End If
  108.     'set the icon, if its nothing, its still ok
  109.     Set Items(ItemCount).Pic = ItemIcon
  110.     Items(ItemCount).Name = Name
  111.     If ItemForeColor = -1 Then
  112.         Items(ItemCount).IForecolor = m_ItemForeColor
  113.     Else
  114.         Items(ItemCount).IForecolor = ItemForeColor
  115.     End If
  116.     If ItemHotForeColor = -1 Then
  117.         Items(ItemCount).IHotForecolor = m_ItemHotForeColor
  118.     Else
  119.         Items(ItemCount).IHotForecolor = ItemHotForeColor
  120.     End If
  121.     If ItemHotBackColor = -1 Then
  122.         Items(ItemCount).IHotBackcolor = m_ItemHotBackColor
  123.     Else
  124.         Items(ItemCount).IHotBackcolor = ItemHotBackColor
  125.     End If
  126. End Function
  127. 'ACHTUNG! DIE FOLGENDEN KOMMENTIERTEN ZEILEN NICHT ENTFERNEN ODER VER
  128. NDERN!
  129. 'MemberInfo=14
  130. Public Sub ShowMenu(Optional X As Long = -1, Optional Y As Long = -1, Optional LeftImage As StdPicture)
  131.     'get the mousepos, and set the menufrm.left & .top
  132.     Dim XY As POINTAPI
  133.     Dim LoopMe As Long
  134.     GetCursorPos XY
  135.     Load MenuFrm
  136.     If X = -1 And Y = -1 Then
  137.         MenuFrm.Left = XY.X * Screen.TwipsPerPixelX
  138.         MenuFrm.Top = XY.Y * Screen.TwipsPerPixelY
  139.     Else
  140.         MenuFrm.Left = X * Screen.TwipsPerPixelX
  141.         MenuFrm.Top = Y * Screen.TwipsPerPixelY
  142.     End If
  143.     Set MenuFrm.Font = UserControl.Font
  144.     Set LeftPic = LeftImage
  145.     MenuFrm.BackColor = m_BackColor
  146.     MenuFrm.Width = 1
  147.     MenuFrm.Height = 1
  148.     'show the form and draw the menu
  149.     MenuFrm.Show
  150.     MenuFrm.DrawMenu , , , True
  151.     MenuClosed = False
  152.     SetCapture MenuFrm.hwnd
  153.     Dim TempText As String, TempIndex As Integer, Raiseevents As Boolean, TempName As String
  154.     'set it into a loop so it checked if the menu is closed,
  155.     'if it is closed, reset the itemdata and raise the
  156.     'itemclick event
  157.     Do
  158.         If MenuClosed = True Then
  159.             'only raise the event it we're on an actual item
  160.             'makes sense because if we are off the form the
  161.             'hotitem is set to -1...
  162.             If HotItem < ItemCount + 2 And HotItem > 0 Then
  163.                 'make sure the item is enabled and not a
  164.                 'seperator...
  165.                 If Items(HotItem - 1).Enabled = True Then
  166.                     TempText = Items(HotItem - 1).Text
  167.                     TempIndex = HotItem
  168.                     TempName = Items(HotItem - 1).Name
  169.                     Raiseevents = True
  170.                 End If
  171.             Else
  172.                 Raiseevents = False
  173.             End If
  174.             ItemCount = -1
  175.             ReDim Items(0)
  176.             Exit Do
  177.         End If
  178.         DoEvents
  179.     Loop
  180.     If Raiseevents = True Then
  181.         RaiseEvent ItemClicked(TempIndex, TempText, TempName)
  182.     End If
  183. End Sub
  184. 'ACHTUNG! DIE FOLGENDEN KOMMENTIERTEN ZEILEN NICHT ENTFERNEN ODER VER
  185. NDERN!
  186. 'MemberInfo=10,0,0,0
  187. Public Property Get ItemForeColor() As OLE_COLOR
  188.     ItemForeColor = m_ItemForeColor
  189. End Property
  190. Public Property Let ItemForeColor(ByVal New_ItemForeColor As OLE_COLOR)
  191.     m_ItemForeColor = New_ItemForeColor
  192.     PropertyChanged "ItemForeColor"
  193. End Property
  194. 'ACHTUNG! DIE FOLGENDEN KOMMENTIERTEN ZEILEN NICHT ENTFERNEN ODER VER
  195. NDERN!
  196. 'MemberInfo=10,0,0,0
  197. Public Property Get ItemHotForeColor() As OLE_COLOR
  198.     ItemHotForeColor = m_ItemHotForeColor
  199. End Property
  200. Public Property Let ItemHotForeColor(ByVal New_ItemHotForeColor As OLE_COLOR)
  201.     m_ItemHotForeColor = New_ItemHotForeColor
  202.     PropertyChanged "ItemHotForeColor"
  203. End Property
  204. 'Eigenschaften f
  205. r Benutzersteuerelement initialisieren
  206. Private Sub UserControl_InitProperties()
  207.     Set UserControl.Font = Ambient.Font
  208.     m_ItemForeColor = m_def_ItemForeColor
  209.     m_ItemHotForeColor = m_def_ItemHotForeColor
  210.     m_Style = m_def_Style
  211.     m_ItemHotBackColor = m_def_ItemHotBackColor
  212.     m_UseIcons = m_def_UseIcons
  213.     m_BackColor = &H8000000F
  214.     m_OpenAnimated = m_def_OpenAnimated
  215.     m_MenuAnimSpeed = m_def_MenuAnimSpeed
  216.     m_UseLeftImage = m_def_UseLeftImage
  217.     m_LeftPicBackColor = m_def_LeftPicBackColor
  218.     m_MouseOverSelectionType = m_def_MouseOverSelectionType
  219. End Sub
  220. 'Eigenschaftenwerte vom Speicher laden
  221. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  222.     Set UserControl.Font = PropBag.ReadProperty("Font", Ambient.Font)
  223.     UserControl.Enabled = PropBag.ReadProperty("Enabled", True)
  224.     m_ItemForeColor = PropBag.ReadProperty("ItemForeColor", m_def_ItemForeColor)
  225.     m_ItemHotForeColor = PropBag.ReadProperty("ItemHotForeColor", m_def_ItemHotForeColor)
  226.     ItemCount = -1
  227.     m_Style = PropBag.ReadProperty("Style", m_def_Style)
  228.     UserControl.BackColor = PropBag.ReadProperty("BackColor", &H8000000F)
  229.     m_ItemHotBackColor = PropBag.ReadProperty("ItemHotBackColor", m_def_ItemHotBackColor)
  230.     m_UseIcons = PropBag.ReadProperty("UseIcons", m_def_UseIcons)
  231.     m_BackColor = UserControl.BackColor
  232.     m_OpenAnimated = PropBag.ReadProperty("OpenAnimated", m_def_OpenAnimated)
  233.     m_MenuAnimSpeed = PropBag.ReadProperty("MenuAnimSpeed", m_def_MenuAnimSpeed)
  234.     m_UseLeftImage = PropBag.ReadProperty("UseLeftImage", m_def_UseLeftImage)
  235.     m_LeftPicBackColor = PropBag.ReadProperty("LeftPicBackColor", m_def_LeftPicBackColor)
  236.     m_MouseOverSelectionType = PropBag.ReadProperty("MouseOverSelectionType", m_def_MouseOverSelectionType)
  237. End Sub
  238. 'Eigenschaftenwerte in den Speicher schreiben
  239. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  240.     Call PropBag.WriteProperty("Font", UserControl.Font, Ambient.Font)
  241.     Call PropBag.WriteProperty("Enabled", UserControl.Enabled, True)
  242.     Call PropBag.WriteProperty("ItemForeColor", m_ItemForeColor, m_def_ItemForeColor)
  243.     Call PropBag.WriteProperty("ItemHotForeColor", m_ItemHotForeColor, m_def_ItemHotForeColor)
  244.     Call PropBag.WriteProperty("Style", m_Style, m_def_Style)
  245.     Call PropBag.WriteProperty("BackColor", UserControl.BackColor, &H8000000F)
  246.     Call PropBag.WriteProperty("ItemHotBackColor", m_ItemHotBackColor, m_def_ItemHotBackColor)
  247.     Call PropBag.WriteProperty("UseIcons", m_UseIcons, m_def_UseIcons)
  248.     Call PropBag.WriteProperty("OpenAnimated", m_OpenAnimated, m_def_OpenAnimated)
  249.     Call PropBag.WriteProperty("MenuAnimSpeed", m_MenuAnimSpeed, m_def_MenuAnimSpeed)
  250.     Call PropBag.WriteProperty("UseLeftImage", m_UseLeftImage, m_def_UseLeftImage)
  251.     Call PropBag.WriteProperty("LeftPicBackColor", m_LeftPicBackColor, m_def_LeftPicBackColor)
  252.     Call PropBag.WriteProperty("MouseOverSelectionType", m_MouseOverSelectionType, m_def_MouseOverSelectionType)
  253. End Sub
  254. 'ACHTUNG! DIE FOLGENDEN KOMMENTIERTEN ZEILEN NICHT ENTFERNEN ODER VER
  255. NDERN!
  256. 'MemberInfo=14,0,0,0
  257. Public Property Get Style() As Style_Type
  258.     Style = m_Style
  259. End Property
  260. Public Property Let Style(ByVal New_Style As Style_Type)
  261.     m_Style = New_Style
  262.     PropertyChanged "Style"
  263. End Property
  264. 'ACHTUNG! DIE FOLGENDEN KOMMENTIERTEN ZEILEN NICHT ENTFERNEN ODER VER
  265. NDERN!
  266. 'MappingInfo=UserControl,UserControl,-1,BackColor
  267. Public Property Get BackColor() As OLE_COLOR
  268. Attribute BackColor.VB_Description = "Returns/sets the background color used to display text and graphics in an object."
  269.     BackColor = UserControl.BackColor
  270. End Property
  271. Public Property Let BackColor(ByVal New_BackColor As OLE_COLOR)
  272.     UserControl.BackColor() = New_BackColor
  273.     PropertyChanged "BackColor"
  274.     m_BackColor = New_BackColor
  275. End Property
  276. 'ACHTUNG! DIE FOLGENDEN KOMMENTIERTEN ZEILEN NICHT ENTFERNEN ODER VER
  277. NDERN!
  278. 'MemberInfo=10,0,0,0
  279. Public Property Get ItemHotBackColor() As OLE_COLOR
  280.     ItemHotBackColor = m_ItemHotBackColor
  281. End Property
  282. Public Property Let ItemHotBackColor(ByVal New_ItemHotBackColor As OLE_COLOR)
  283.     m_ItemHotBackColor = New_ItemHotBackColor
  284.     PropertyChanged "ItemHotBackColor"
  285. End Property
  286. 'ACHTUNG! DIE FOLGENDEN KOMMENTIERTEN ZEILEN NICHT ENTFERNEN ODER VER
  287. NDERN!
  288. 'MemberInfo=0,0,0,0
  289. Public Property Get UseIcons() As Boolean
  290. Attribute UseIcons.VB_Description = "Use Icons next to text or not?"
  291.     UseIcons = m_UseIcons
  292. End Property
  293. Public Property Let UseIcons(ByVal New_UseIcons As Boolean)
  294.     m_UseIcons = New_UseIcons
  295.     PropertyChanged "UseIcons"
  296. End Property
  297. 'ACHTUNG! DIE FOLGENDEN KOMMENTIERTEN ZEILEN NICHT ENTFERNEN ODER VER
  298. NDERN!
  299. 'MemberInfo=0,0,0,0
  300. Public Property Get OpenAnimated() As Boolean
  301.     OpenAnimated = m_OpenAnimated
  302. End Property
  303. Public Property Let OpenAnimated(ByVal New_OpenAnimated As Boolean)
  304.     m_OpenAnimated = New_OpenAnimated
  305.     PropertyChanged "OpenAnimated"
  306. End Property
  307. 'ACHTUNG! DIE FOLGENDEN KOMMENTIERTEN ZEILEN NICHT ENTFERNEN ODER VER
  308. NDERN!
  309. 'MemberInfo=12,0,0,200
  310. Public Property Get MenuAnimSpeed() As Single
  311.     MenuAnimSpeed = m_MenuAnimSpeed
  312. End Property
  313. Public Property Let MenuAnimSpeed(ByVal New_MenuAnimSpeed As Single)
  314.     m_MenuAnimSpeed = New_MenuAnimSpeed
  315.     PropertyChanged "MenuAnimSpeed"
  316. End Property
  317. 'ACHTUNG! DIE FOLGENDEN KOMMENTIERTEN ZEILEN NICHT ENTFERNEN ODER VER
  318. NDERN!
  319. 'MemberInfo=0,0,0,0
  320. Public Property Get UseLeftImage() As Boolean
  321.     UseLeftImage = m_UseLeftImage
  322. End Property
  323. Public Property Let UseLeftImage(ByVal New_UseLeftImage As Boolean)
  324.     m_UseLeftImage = New_UseLeftImage
  325.     PropertyChanged "UseLeftImage"
  326. End Property
  327. 'ACHTUNG! DIE FOLGENDEN KOMMENTIERTEN ZEILEN NICHT ENTFERNEN ODER VER
  328. NDERN!
  329. 'MemberInfo=10,0,0,0
  330. Public Property Get LeftPicBackColor() As OLE_COLOR
  331.     LeftPicBackColor = m_LeftPicBackColor
  332. End Property
  333. Public Property Let LeftPicBackColor(ByVal New_LeftPicBackColor As OLE_COLOR)
  334.     m_LeftPicBackColor = New_LeftPicBackColor
  335.     PropertyChanged "LeftPicBackColor"
  336. End Property
  337. 'ACHTUNG! DIE FOLGENDEN KOMMENTIERTEN ZEILEN NICHT ENTFERNEN ODER VER
  338. NDERN!
  339. 'MemberInfo=14,0,0,0
  340. Public Property Get MouseOverSelectionType() As Sel_Type
  341.     MouseOverSelectionType = m_MouseOverSelectionType
  342. End Property
  343. Public Property Let MouseOverSelectionType(ByVal New_MouseOverSelectionType As Sel_Type)
  344.     m_MouseOverSelectionType = New_MouseOverSelectionType
  345.     PropertyChanged "MouseOverSelectionType"
  346. End Property
  347.